package edu.zut.main.socket;

import java.io.*;
import java.net.URL;
import java.net.URLConnection;

public class URLDown {

    public static void main(String[] args) throws IOException {
        //将网络资源下载下来
        String articleUrl = "https://blog.csdn.net/allenfoxxxxx/article/details/90707505";
        //基于http的url连接构建url对象
        URL url = new URL(articleUrl);
        //打开url连接
        URLConnection connection = url.openConnection();
        //基于url连接获取输入流读取网络数据
        BufferedInputStream bis = new BufferedInputStream(connection.getInputStream());
        //将网络资源保存到本地，本地文件的名字建议随机生成
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File("./java9070.html")));

        int len;
        byte[] buffer = new byte[1024];
        while ((len =bis.read(buffer)) != -1){
            bos.write(buffer,0,len);
            bos.flush();
        }
        bos.close();
        bis.close();

    }
}
